package heraclito;

import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

public class BemVindo extends javax.swing.JPanel {

    protected HeraclitoView Principal; //Controle de tela para chamar as funções Novo e Exemplo

    public BemVindo(HeraclitoView H) {
        initComponents();
        Principal = H; //Carrega a variavel principal
        loginRealizado.setVisible(false);
    }

    @Action
    public void AcaoNovo() {
        Principal.NovoTeorema(); //Chama a tela de novo teorema a partir da tela principal
    }

    @Action
    public void AcaoExemplo() {
        Principal.AbrirExemplo(); //Chama a tela de exemplos a partir da tela principal
    }

    @Action
    public void AcaoProvasExistentes() {
        Principal.AcaoProvasExistentes();
    }

    @Action
    public void AcaoManual() {
        Principal.AcaoManual();
    }

    @Action
    public void AcaoLoginLogoff() {
        if (jButton1.getText().equalsIgnoreCase("Realizar logoff")) {
            this.RealizaLogoff();
        } else {
            try {
                this.RealizaLogin();
            } catch (Exception ex) {
                ex.printStackTrace();
                username.setText("");
                password.setText("");
                JOptionPane.showMessageDialog(null, "Erro ao tentar conexão com servidor.");
            }
        }
    }

    private void RealizaLogin() {
        if (Principal.RealizaLogin(username.getText(), password.getText())) {
            username.setVisible(false);
            password.setVisible(false);
            jButton1.setText("Realizar logoff");
            jLabel5.setVisible(false);
            jLabel6.setVisible(false);
            jLabel7.setVisible(false);
            jLabel8.setVisible(false);
            loginRealizado.setVisible(true);
        } else {
            username.setText("");
            password.setText("");
            JOptionPane.showMessageDialog(null, "Erro no username ou senha!");
        }
    }

    private void RealizaLogoff() {
        Principal.RealizaLogoff();
        username.setText("");
        password.setText("");
        username.setVisible(true);
        password.setVisible(true);
        jButton1.setText("Realizar login");
        jLabel5.setVisible(true);
        jLabel6.setVisible(true);
        jLabel7.setVisible(true);
        jLabel8.setVisible(true);
        loginRealizado.setVisible(false);
    }

    public void setUsernamePassword(String param[]) {
        username.setText(param[0]);
        password.setText(param[1]);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        btnNovo = new javax.swing.JButton();
        btnExemplos = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        btnManual = new javax.swing.JButton();
        btnProvasExistentes = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        javax.swing.JLabel imageLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        loginRealizado = new javax.swing.JLabel();
        username = new javax.swing.JTextField();
        password = new javax.swing.JPasswordField();

        setMinimumSize(new java.awt.Dimension(600, 572));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(1320, 607));
        setLayout(new java.awt.GridBagLayout());

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(heraclito.HeraclitoApp.class).getContext().getResourceMap(BemVindo.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(74, 33, 0, 0);
        add(jLabel1, gridBagConstraints);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(heraclito.HeraclitoApp.class).getContext().getActionMap(BemVindo.class, this);
        btnNovo.setAction(actionMap.get("AcaoNovo")); // NOI18N
        btnNovo.setIcon(resourceMap.getIcon("btnNovo.icon")); // NOI18N
        btnNovo.setText(resourceMap.getString("btnNovo.text")); // NOI18N
        btnNovo.setMaximumSize(new java.awt.Dimension(215, 73));
        btnNovo.setMinimumSize(new java.awt.Dimension(215, 73));
        btnNovo.setName("btnNovo"); // NOI18N
        btnNovo.setPreferredSize(new java.awt.Dimension(215, 73));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 38;
        gridBagConstraints.ipady = 25;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(45, 0, 0, 0);
        add(btnNovo, gridBagConstraints);

        btnExemplos.setAction(actionMap.get("AcaoExemplo")); // NOI18N
        btnExemplos.setIcon(resourceMap.getIcon("btnExemplos.icon")); // NOI18N
        btnExemplos.setText(resourceMap.getString("btnExemplos.text")); // NOI18N
        btnExemplos.setMaximumSize(new java.awt.Dimension(215, 73));
        btnExemplos.setMinimumSize(new java.awt.Dimension(215, 73));
        btnExemplos.setName("btnExemplos"); // NOI18N
        btnExemplos.setPreferredSize(new java.awt.Dimension(215, 73));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 6;
        gridBagConstraints.ipadx = 38;
        gridBagConstraints.ipady = 25;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        add(btnExemplos, gridBagConstraints);

        jSeparator1.setName("jSeparator1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 37;
        gridBagConstraints.ipadx = 1152;
        gridBagConstraints.ipady = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 0);
        add(jSeparator1, gridBagConstraints);

        jSeparator2.setName("jSeparator2"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 38;
        gridBagConstraints.ipadx = 1162;
        gridBagConstraints.ipady = 11;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 0);
        add(jSeparator2, gridBagConstraints);

        btnManual.setAction(actionMap.get("AcaoManual")); // NOI18N
        btnManual.setIcon(resourceMap.getIcon("btnManual.icon")); // NOI18N
        btnManual.setText(resourceMap.getString("btnManual.text")); // NOI18N
        btnManual.setMaximumSize(new java.awt.Dimension(215, 73));
        btnManual.setMinimumSize(new java.awt.Dimension(215, 73));
        btnManual.setName("btnManual"); // NOI18N
        btnManual.setPreferredSize(new java.awt.Dimension(215, 73));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 17;
        gridBagConstraints.ipady = 25;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
        add(btnManual, gridBagConstraints);

        btnProvasExistentes.setAction(actionMap.get("AcaoProvasExistentes")); // NOI18N
        btnProvasExistentes.setIcon(resourceMap.getIcon("btnProvasExistentes.icon")); // NOI18N
        btnProvasExistentes.setText(resourceMap.getString("btnProvasExistentes.text")); // NOI18N
        btnProvasExistentes.setName("btnProvasExistentes"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.ipadx = 17;
        gridBagConstraints.ipady = 25;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(45, 6, 0, 0);
        add(btnProvasExistentes, gridBagConstraints);

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        add(jLabel2, gridBagConstraints);

        imageLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/heraclito/resources/heraclito.png"))); // NOI18N
        imageLabel1.setName("imageLabel1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 41, 0, 0);
        add(imageLabel1, gridBagConstraints);

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 19;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(1, 127, 0, 0);
        add(jLabel3, gridBagConstraints);

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 30;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 58, 0, 0);
        add(jLabel4, gridBagConstraints);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator3.setName("jSeparator3"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridheight = 20;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.ipady = 273;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 25, 0);
        add(jSeparator3, gridBagConstraints);

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 31;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(47, 52, 0, 0);
        add(jLabel5, gridBagConstraints);

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = 32;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 4, 0, 0);
        add(jLabel6, gridBagConstraints);

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.gridheight = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.ipady = 14;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 64, 0, 0);
        add(jLabel7, gridBagConstraints);

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 18;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.ipady = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(13, 164, 0, 0);
        add(jLabel8, gridBagConstraints);

        jButton1.setAction(actionMap.get("AcaoLoginLogoff")); // NOI18N
        jButton1.setFont(resourceMap.getFont("jButton1.font")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.gridheight = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(27, 231, 0, 0);
        add(jButton1, gridBagConstraints);

        loginRealizado.setFont(resourceMap.getFont("loginRealizado.font")); // NOI18N
        loginRealizado.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        loginRealizado.setText(resourceMap.getString("loginRealizado.text")); // NOI18N
        loginRealizado.setName("loginRealizado"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 10;
        gridBagConstraints.ipady = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 196, 0, 0);
        add(loginRealizado, gridBagConstraints);

        username.setName("username"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = 20;
        gridBagConstraints.gridheight = 5;
        gridBagConstraints.ipadx = 112;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 17, 0, 0);
        add(username, gridBagConstraints);

        password.setText(resourceMap.getString("password.text")); // NOI18N
        password.setName("password"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 18;
        gridBagConstraints.gridwidth = 20;
        gridBagConstraints.ipadx = 112;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(17, 17, 0, 0);
        add(password, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExemplos;
    private javax.swing.JButton btnManual;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnProvasExistentes;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JLabel loginRealizado;
    private javax.swing.JPasswordField password;
    private javax.swing.JTextField username;
    // End of variables declaration//GEN-END:variables
}
